package com.enjoyor.soa.traffic.frame.configure;

import java.util.HashMap;
import java.util.Map;


import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.CharacterEncodingFilter;

import com.enjoyor.soa.traffic.frame.security.fifter.SSOFilter;

@Configuration
@ConfigurationProperties(prefix = "sso.client")
public class SSOFilterConfig {

    public Map<String, String> filter = new HashMap<String, String>();

    @Bean
    public CharacterEncodingFilter characterEncodingFilter() {
        CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
        characterEncodingFilter.setEncoding("UTF-8");
        characterEncodingFilter.setForceEncoding(true);
        return characterEncodingFilter;
    }

    @Bean
    public FilterRegistrationBean SSOFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new SSOFilter());
        registration.addUrlPatterns(getFilter().get("urlPatterns"));
        registration.setInitParameters(getFilter());
        registration.setName("SSOFilter");
        registration.setEnabled(true);
        registration.setOrder(1);
        return registration;
    }

    public Map<String, String> getFilter() {
        return filter;
    }

    public void setFilter(Map<String, String> filter) {
        this.filter = filter;
    }

}
